/*
 * draw.c
 *
 *  Created on: Jul 27, 2013
 *      Author: derekmorris
 */

#include <engine.h>

void drawTriangle(const Vector3* p0, const Vector3* p1, const Vector3* p2, const Vector4* pColor, uint id0, uint id1)
{
	float gTriangleVertices2[7*3];

	gTriangleVertices2[0] = p0->x;
	gTriangleVertices2[1] = p0->y;
	gTriangleVertices2[2] = p0->z;
	gTriangleVertices2[3] = pColor->x;
	gTriangleVertices2[4] = pColor->y;
	gTriangleVertices2[5] = pColor->z;
	gTriangleVertices2[6] = pColor->w;

	gTriangleVertices2[7] = p1->x;
	gTriangleVertices2[8] = p1->y;
	gTriangleVertices2[9] = p1->z;
	gTriangleVertices2[10] = pColor->x;
	gTriangleVertices2[11] = pColor->y;
	gTriangleVertices2[12] = pColor->z;
	gTriangleVertices2[13] = pColor->w;

	gTriangleVertices2[14] = p2->x;
	gTriangleVertices2[15] = p2->y;
	gTriangleVertices2[16] = p2->z;
	gTriangleVertices2[17] = pColor->x;
	gTriangleVertices2[18] = pColor->y;
	gTriangleVertices2[19] = pColor->z;
	gTriangleVertices2[20] = pColor->w;

	glVertexAttribPointer(id0, 3, GL_FLOAT, GL_FALSE, 7 * sizeof(float), gTriangleVertices2);
	glEnableVertexAttribArray(id0);

	glVertexAttribPointer(id1, 4, GL_FLOAT, GL_FALSE, 7 * sizeof(float), gTriangleVertices2 + 3);
	glEnableVertexAttribArray(id1);

	glDrawArrays(GL_TRIANGLES, 0, 3);
}

void drawCube(Matrix4x4* pWorldMatrix, uint id0, uint id1)
{
	float cubeVertices2[7*8];

	// line 0 ///////////////

	// front top left
	cubeVertices2[0] = -0.5f;
	cubeVertices2[1] = 0.5f;
	cubeVertices2[2] = 0.0f;
	cubeVertices2[3] = 1.0f;
	cubeVertices2[4] = 1.0f;
	cubeVertices2[5] = 1.0f;
	cubeVertices2[6] = 1.0f;

	// front top right
	cubeVertices2[7] = 0.5f;
	cubeVertices2[8] = 0.5f;
	cubeVertices2[9] = 0.0f;
	cubeVertices2[10] = 1.0f;
	cubeVertices2[11] = 1.0f;
	cubeVertices2[12] = 1.0f;
	cubeVertices2[13] = 1.0f;

	// line 1 ///////////////

	// front top left
	cubeVertices2[14] = -0.5f;
	cubeVertices2[15] = 0.5f;
	cubeVertices2[16] = 0.0f;
	cubeVertices2[17] = 1.0f;
	cubeVertices2[18] = 1.0f;
	cubeVertices2[19] = 1.0f;
	cubeVertices2[20] = 1.0f;

	// front bottom left
	cubeVertices2[21] = -0.5f;
	cubeVertices2[22] = -0.5f;
	cubeVertices2[23] = 0.0f;
	cubeVertices2[24] = 1.0f;
	cubeVertices2[25] = 1.0f;
	cubeVertices2[26] = 1.0f;
	cubeVertices2[27] = 1.0f;

	// line 2 ///////////////

	// front bottom left
	cubeVertices2[28] = -0.5f;
	cubeVertices2[29] = -0.5f;
	cubeVertices2[30] = 0.0f;
	cubeVertices2[31] = 1.0f;
	cubeVertices2[32] = 1.0f;
	cubeVertices2[33] = 1.0f;
	cubeVertices2[34] = 1.0f;

	// front bottom right
	cubeVertices2[35] = 0.5f;
	cubeVertices2[36] = -0.5f;
	cubeVertices2[37] = 0.0f;
	cubeVertices2[38] = 1.0f;
	cubeVertices2[39] = 1.0f;
	cubeVertices2[40] = 1.0f;
	cubeVertices2[41] = 1.0f;

	// line 3 ///////////////

	// front top right
	cubeVertices2[42] = 0.5f;
	cubeVertices2[43] = 0.5f;
	cubeVertices2[44] = 0.0f;
	cubeVertices2[45] = 1.0f;
	cubeVertices2[46] = 1.0f;
	cubeVertices2[47] = 1.0f;
	cubeVertices2[48] = 1.0f;

	// front bottom right
	cubeVertices2[49] = 0.5f;
	cubeVertices2[50] = -0.5f;
	cubeVertices2[51] = 0.0f;
	cubeVertices2[52] = 1.0f;
	cubeVertices2[53] = 1.0f;
	cubeVertices2[54] = 1.0f;
	cubeVertices2[55] = 1.0f;

	glVertexAttribPointer(id0, 3, GL_FLOAT, GL_FALSE, 7 * sizeof(float), cubeVertices2);
	glEnableVertexAttribArray(id0);

	glVertexAttribPointer(id1, 4, GL_FLOAT, GL_FALSE, 7 * sizeof(float), cubeVertices2 + 3);
	glEnableVertexAttribArray(id1);

	glDrawArrays(GL_LINES, 0, 8);
}



